<?php
require_once 'Zend/Controller/Action.php';
class Admin_FeedbackController extends Sunnet_Controller_Action
{
	var $_arrParam;
	public function init()
    {
//    	Truyền các tham số nhận được ra view
    	$this->_arrParam = $this->_request->getParams();
    	$this->view->arrParam = $this->_arrParam;
    	if (empty($this->_arrParam['page'])) {
    		$this->_arrParam['page'] = 1;
    	}
    	if (empty($this->_arrParam['line_per_page'])) {
    		$this->_arrParam['line_per_page'] = 10;
    	}
        Zend_Loader::loadClass('Admin_Models_MenuModel');
         $db = new Admin_Models_MenuModel();
         $mainmenu = $db->loadmainmenu();
         $this->view->mainmenu = $mainmenu; 
    }

    public function preDispatch(){
         $template_path = TEMPLATE_PATH . "/admin/default/";
		$this->loadTemplate($template_path,'template.ini','template');
        $auth = Zend_Auth::getInstance();
        if ((!$auth->hasIdentity() || !$auth->getIdentity()->admin) && ($this->_arrParam['action'] != 'login')) {
    		$this->_forward('login','index','admin',array('action'	=> 'login'));//,$this->_arrParam);
    	}
        
    }
    public function indexAction(){
        Zend_Loader::loadClass('Admin_Models_FeedbackModel');
        $model = new Admin_Models_FeedbackModel();
        $search = $this->_request->getParam('search');
        $search_end = $this->_request->getParam('search_end');
        $currentPage = 1;
        $i = $this->_getParam('page',1);
	if(!empty($i))
	{
		$currentPage = $i;
	}
	$paginator = Zend_Paginator::factory($model->loadlistmess());
	$paginator->setItemCountPerPage(10)
	->setPageRange(4)
	->setCurrentPageNumber($currentPage);
	$this->view->paginator = $paginator;
        $this->view->data=$model->loadlistmess();
         if($search!= null){    
            
         $listmess = $model->search($search,$search_end);
         
         $currentPage = 1;
		$i = $this->_getParam('page',1);
		if(!empty($i))
		{
			$currentPage = $i;
		}
		$paginator = Zend_Paginator::factory( $listmess);

		$paginator->setItemCountPerPage(10)
		->setPageRange(4)
		->setCurrentPageNumber($currentPage);
		$this->view->paginator = $paginator;
                $this->view->data =$paginator;
         }   
        
    }
    public function delAction(){
             Zend_Loader::loadClass('Admin_Models_FeedbackModel');
             $model = new Admin_Models_FeedbackModel();
             $id = $this->_request->getParam('id');
             $result = $model->delete('id ='.$id);
             $this->_redirect('/admin/feedback/index/');
    }
}
?>
